<template>
	<div class="classify" v-show="isSearch">
		<div class="classify__search">
			<span @click="close">关闭</span>
			<s-simulation-search-input v-model="searchData" placeholder="请输入图书名称..."></s-simulation-search-input>
		</div>
		<ul class="classify__list">
			<li v-for="item in classify" @click="close">
				<router-link :to="item.jump">
					<svg class="icon" aria-hidden="true">
						<use v-bind:xlink:href="item.icon"></use>
					</svg>
					<span>{{item.name}}</span>
				</router-link>
			</li>
		</ul>
		<div class="classify__subject">
			<h2>学科分类</h2>
			<ul class="classify__subject--wrap">
				<li v-for="item in classify_subject" @click="close">
					<router-link :to="item.jump">{{item.name}}</router-link>
				</li>
			</ul>
		</div>
	</div>
</template>

<script>
	import { fetchClassifyBooks } from "../../../api/api.js"
	export default {
		created() {
			this.getClassify();
		},
		data() {
			return {
				classify: "",
				classify_subject: "",
				searchData: ''
			}
		},
		computed: {
			isSearch() {
				return this.$parent.isClassify;
			}
		},
		methods: {
			getClassify() {
				fetchClassifyBooks().then( res => {
					this.classify = res.data.result.classify;
					this.classify_subject = res.data.result.classify_subject;
				} ).catch( err => {
					alert(err);
					console.log(err);
				} );
			},
			close() {
				this.$parent.isClassify = false;
			}
		}
	}
</script>

<style scoped lang="scss">
	.classify {
		width: 20rem;
		position: absolute;
		left: 50%;
		top: 0;
		bottom: 0;
		transform: translate(-50%,0);
		background: #fff;
		z-index: 2;
		overflow-y: auto;
	}
	
	.classify__search {
		padding: $com-padding-lr-base;
		border-bottom: 1px solid #eee;
		display: flex;
		align-items: center;
		span {
			font-size: $font-md;
			color: $color-success;
		}
	}
	
	.classify__list {
		display: flex;
		flex-wrap: wrap;
		border-bottom: 1px solid #eee;
		li {
			flex: 0 0 33%;
			padding: rem(24) 0;
			a {
				width: 100%;
				margin: auto;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				.icon {
					font-size: $classify-icon-width;
					margin-bottom: 3px;
				}
				span {
					font-size: $font-sm;
				}
			}
		}
	}
	.classify__subject {
		h2 {
			padding: .7rem 1rem;
			font-size: $font-lg;
			font-weight: normal;
			color: #3af;
		}
	}
	.classify__subject--wrap {
		display: flex;
		flex-wrap: wrap;
		margin-top: 10px;
		li {
			text-indent: rem(20);
			padding: rem(7.5) 0;
			flex: 0 0 50%;
			border-top: 1px solid #ccc;
			a {
				color: $color-success;
				font-size: $font-sm;
			}
		}
		li:nth-of-type(2n + 1) {
			border-right: 1px solid #ccc;
		}
		li:nth-last-of-type(-n + 2) {
			border-bottom: 1px solid #ccc;
		}
	}
</style>